﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace RexToy.UI.WinForm.Pmlx
{
    class IsolateLocator : IPmlxFileLocator
    {
        private string GetPath(UserControl uc)
        {
            string folder = System.Environment.CurrentDirectory;
            return Path.Combine(folder, uc.GetType().Name + PmlxConstant.UC_EXTENSION);
        }

        private string GetPath(Form f)
        {
            string folder = System.Environment.CurrentDirectory;
            return Path.Combine(folder, f.GetType().Name + PmlxConstant.FORM_EXTENSION);
        }

        public PmlxDoc ReadPmlxFile(UserControl uc)
        {
            string path = GetPath(uc);
            return PmlxDoc.Load(path);
        }

        public PmlxDoc ReadPmlxFile(Form f)
        {
            string path = GetPath(f);
            return PmlxDoc.Load(path);
        }

        public bool ExistPmlxFile(UserControl uc)
        {
            string path = GetPath(uc);
            return File.Exists(path);
        }

        public bool ExistPmlxFile(Form f)
        {
            string path = GetPath(f);
            return File.Exists(path);
        }
    }
}
